<?php

include_once '../util/db/Conn.php';
include_once '../util/ArrayList.php';
include_once '../util/db/model/ProdSubType.php';

class ProdSubTypeDBUtil {
	protected $dbConn;
	private $tabName = "prod_sub_type";
	function __construct() {
		$this->dbConn = new DBConn ();
		header ( "Content-Type:text/html; charset=utf-8" );
	}
	
	public function open() {
		$this->dbConn->open ();
	
	}
	
	public function close() {
		$this->dbConn->close ();
	}
	
	public function queryAll() {
		$this->open ();
		$arrayList = new ArrayList ();
		$sql = "select * from `$this->tabName`";
		$result = mysql_query ( $sql );
		while ( $row = @mysql_fetch_array ( $result ) ) {
			$arrayList->add ( $this->fill ( $row ) );
		}
		$this->close ();
		return $arrayList;
	}
	
	/**
	 * Enter description here ...
	 */
	private function fill($row) {
		$prodSubType = new ProdSubType ();
		$prodSubType->setPst_id ( $row ['pst_id'] );
		$prodSubType->setType ( $row ['type'] );
		$prodSubType->setSub_type ( $row ['sub_type'] );
		return $prodSubType;
	}

	public function queryByType($type) {
		$this->open ();
		$arrayList = new ArrayList ();
		$sql = "select * from `$this->tabName` where type=$type ";
		$result = mysql_query ( $sql );
		while ( $row = @mysql_fetch_array ( $result ) ) {
			$arrayList->add ( $this->fill ( $row ) );
		}
		$this->close ();
		return $arrayList;
	}
}
?>